home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Treiber / Misc / Mroocheck / FreeWheel / Source / PrefsWin.c < prev    next >
C/C++ Source or Header  |  2000-04-20  |  10KB  |  359 lines

  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. #include <exec/types.h>
  6. #include <intuition/intuition.h>
  7. #include <intuition/screens.h>
  8.  
  9. #include <clib/exec_protos.h>
  10. #include <clib/intuition_protos.h>
  11. #include <clib/gadtools_protos.h>
  12.  
  13. #include "Cx.h"
  14. #include "Prefs.h"
  15. #include "GUI.h"
  16. #include "WheelMouse.h"
  17.  
  18. #include "ButtonWin.h"
  19. #include "ScrollWin.h"
  20. #include "PrefsWin.h"
  21.  
  22. #define WINDOWMODE_ID 1
  23. #define SAVE_ID 8
  24. #define HIDE_ID 9
  25. #define QUIT_ID 10
  26. #define HOTKEY_ID 11
  27. #define XSPEED_ID 12
  28. #define YSPEED_ID 13
  29. #define CLICKFRONT_ID 14
  30. #define CLICKBACK_ID 15
  31. #define SETBUTTONS_ID 16
  32. #define SETSCROLL_ID 17
  33.  
  34. BOOL PrefsWin_Show(struct PrefsWinContext *pwc);
  35. void PrefsWin_Hide(struct PrefsWinContext *pwc);
  36. BOOL PrefsWin_Handle(struct PrefsWinContext *pwc,unsigned long sigs);
  37. void PrefsWin_Dispose(struct PrefsWinContext *pwc);
  38.  
  39. extern struct WheelMouseContext *MyWM;
  40. extern struct CxContext *MyCx;
  41.  
  42. char *PWinGadTitles[]=
  43. {
  44.   "Scroll window:",
  45.   "Mouse speed X: %ld%%",
  46.   "Mouse speed Y: %ld%%",
  47.   "Click to front:",
  48.   "Hot key:",
  49.   "Click to back:",
  50.   "Set buttons...",
  51.   "Set scrolling...",
  52.   NULL
  53. };
  54.  
  55. #define SCROLLWINDOW_TITLE 0
  56. #define MOUSESPEEDX_TITLE 1
  57. #define MOUSESPEEDY_TITLE 2
  58. #define CLICKFRONT_TITLE 3
  59. #define HOTKEY_TITLE 4
  60. #define CLICKBACK_TITLE 5
  61. #define SETBUTTONS_TITLE 6
  62. #define SETSCROLL_TITLE 7
  63.  
  64. BOOL PrefsWin_Show(struct PrefsWinContext *pwc)
  65. {
  66.   struct Gadget *gg;
  67.   int width,width2,leftedge,topedge;
  68.   int winleft,wintop;
  69.  
  70.   if(pwc->Visible)
  71.     return(FALSE);
  72.  
  73.   if(!(pwc->Screen=LockPubScreen(NULL)))
  74.     return(FALSE);
  75.  
  76.   if(!(pwc->GUI=GUI_Create(pwc->Screen,pwc->Screen->Font,8,8)))
  77.   {
  78.     pwc->Hide(pwc);
  79.     return(FALSE);
  80.   }
  81.  
  82.   GUI_StringTab(pwc->GUI,PWinGadTitles);
  83.  
  84.   width=GUI_MaxStringWidth(pwc->GUI,MyWM->WindowModeNames);
  85.   width2=GUI_MaxStringWidth(pwc->GUI,MyWM->MidButton.ClickModeNames);
  86.   if(width2>width) width=width2;
  87.   width2=GUI_MaxStringWidth(pwc->GUI,MyWM->FourthButton.ClickModeNames);
  88.   if(width2>width) width=width2;
  89.  
  90.   pwc->GUI->InnerWidth=pwc->GUI->TabStop+width+64;
  91.  
  92.   gg=GUI_BuildSliderFormatted(pwc->GUI,PWinGadTitles[MOUSESPEEDX_TITLE],33,300,100,XSPEED_ID);
  93.   GT_SetGadgetAttrs(gg,NULL,NULL,GTSL_Level,
  94.                     pwc->Prefs->GetLong(pwc->Prefs,"XMouseSpeed",100),TAG_DONE);
  95.  
  96.   gg=GUI_BuildSliderFormatted(pwc->GUI,PWinGadTitles[MOUSESPEEDY_TITLE],33,300,100,YSPEED_ID);
  97.   GT_SetGadgetAttrs(gg,NULL,NULL,GTSL_Level,
  98.                     pwc->Prefs->GetLong(pwc->Prefs,"YMouseSpeed",100),TAG_DONE);
  99.  
  100.   gg=GUI_BuildCheckBox(pwc->GUI,PWinGadTitles[CLICKFRONT_TITLE],CLICKFRONT_ID);
  101.   GT_SetGadgetAttrs(gg,NULL,NULL,GTCB_Checked,
  102.                     pwc->Prefs->GetLong(pwc->Prefs,"ClickFront",TRUE),TAG_DONE);
  103.  
  104.   gg=GUI_BuildCheckBox(pwc->GUI,PWinGadTitles[CLICKBACK_TITLE],CLICKBACK_ID);
  105.   GT_SetGadgetAttrs(gg,NULL,NULL,GTCB_Checked,
  106.                     pwc->Prefs->GetLong(pwc->Prefs,"ClickBack",FALSE),TAG_DONE);
  107.  
  108.   gg=GUI_BuildString(pwc->GUI,PWinGadTitles[HOTKEY_TITLE],255,HOTKEY_ID);
  109.   GT_SetGadgetAttrs(gg,NULL,NULL,GTST_String,
  110.                     pwc->Prefs->GetString(pwc->Prefs,"Hot Key","ctrl alt m"),TAG_DONE);
  111.  
  112.   GUI_StringTab(pwc->GUI,NULL);
  113.  
  114.   width=pwc->GUI->InnerWidth;
  115.   leftedge=pwc->GUI->BorderLeft;
  116.   topedge=pwc->GUI->InnerHeight;
  117.  
  118.   pwc->GUI->InnerWidth/=2;
  119.   gg=GUI_BuildWideButton(pwc->GUI,PWinGadTitles[SETBUTTONS_TITLE],SETBUTTONS_ID);
  120.  
  121.   pwc->GUI->InnerHeight=topedge;
  122.   pwc->GUI->BorderLeft+=width/2;
  123.   gg=GUI_BuildWideButton(pwc->GUI,PWinGadTitles[SETSCROLL_TITLE],SETSCROLL_ID);
  124.  
  125.   pwc->GUI->BorderLeft=leftedge;
  126.   pwc->GUI->InnerWidth=width;
  127.   topedge=pwc->GUI->InnerHeight;
  128.  
  129.   pwc->GUI->InnerWidth=width/3;
  130.   GUI_BuildWideButton(pwc->GUI,"Save",SAVE_ID);
  131.  
  132.   pwc->GUI->InnerHeight=topedge;
  133.   pwc->GUI->BorderLeft+=width/3;
  134.   GUI_BuildWideButton(pwc->GUI,"Hide",HIDE_ID);
  135.  
  136.   pwc->GUI->InnerHeight=topedge;
  137.   pwc->GUI->BorderLeft+=width/3;
  138.   GUI_BuildWideButton(pwc->GUI,"Quit",QUIT_ID);
  139.  
  140.   pwc->GUI->BorderLeft=leftedge;
  141.   pwc->GUI->InnerWidth=width;
  142.  
  143.   if(!(pwc->GUI->LastGadget))
  144.   {
  145.     pwc->Hide(pwc);
  146.     return(FALSE);
  147.   }
  148.  
  149.   winleft=pwc->Prefs->GetLong(pwc->Prefs,"MainLeft",0);
  150.   wintop=pwc->Prefs->GetLong(pwc->Prefs,"MainTop",1+pwc->Screen->BarHeight);
  151.  
  152.   if(!(pwc->Window=OpenWindowTags(NULL,WA_Left,winleft,
  153.                                        WA_Top,wintop,
  154.                                        WA_InnerWidth,pwc->GUI->InnerWidth,
  155.                                        WA_InnerHeight,pwc->GUI->InnerHeight,
  156.                                        WA_IDCMP,IDCMP_REFRESHWINDOW|IDCMP_CLOSEWINDOW|pwc->GUI->IDCMP,
  157.                                        WA_SizeGadget,FALSE,WA_DragBar,TRUE,
  158.                                        WA_DepthGadget,TRUE,WA_CloseGadget,TRUE,
  159.                                        WA_NewLookMenus,TRUE,
  160.                                        WA_Activate,FALSE,
  161.                                        WA_Title,"FreeWheel V2.0",TAG_DONE)))
  162.   {
  163.     pwc->Hide(pwc);
  164.     return(FALSE);
  165.   }
  166.  
  167.   pwc->GUI->Attach(pwc->GUI,pwc->Window);
  168.  
  169.   pwc->Signals=1<<pwc->Window->UserPort->mp_SigBit;
  170.   pwc->Signals|=pwc->ButtonWin->Signals;
  171.   pwc->Signals|=pwc->ScrollWin->Signals;
  172.  
  173.   pwc->Visible=TRUE;
  174.   return(TRUE);
  175. }
  176.  
  177.  
  178. void PrefsWin_Hide(struct PrefsWinContext *pwc)
  179. {
  180.   if(pwc->Window)
  181.     CloseWindow(pwc->Window);
  182.   pwc->Window=FALSE;
  183.   pwc->Signals=0;
  184.  
  185.   if(pwc->GUI)
  186.     pwc->GUI->Dispose(pwc->GUI);
  187.   pwc->GUI=NULL;
  188.  
  189.   if(pwc->Screen)
  190.     UnlockPubScreen(NULL,pwc->Screen);
  191.   pwc->Screen=FALSE;
  192.  
  193.   if(pwc->Visible)
  194.     pwc->Visible=FALSE;
  195.  
  196.   if(pwc->ButtonWin)
  197.     pwc->ButtonWin->Hide(pwc->ButtonWin);
  198.  
  199.   if(pwc->ScrollWin)
  200.     pwc->ScrollWin->Hide(pwc->ScrollWin);
  201.  
  202.   pwc->Signals=0;
  203. }
  204.  
  205.  
  206. void PrefsWin_Dispose(struct PrefsWinContext *pwc)
  207. {
  208.   if(pwc)
  209.   {
  210.     if(pwc->Visible)
  211.       pwc->Hide(pwc);
  212.     if(pwc->ButtonWin)
  213.       pwc->ButtonWin->Dispose(pwc->ButtonWin);
  214.     if(pwc->ScrollWin)
  215.       pwc->ScrollWin->Dispose(pwc->ScrollWin);
  216.     free(pwc);
  217.   }
  218. }
  219.  
  220.  
  221. struct PrefsWinContext *PrefsWin_Create(struct PrefsGroup *pg)
  222. {
  223.   struct PrefsWinContext *pwc;
  224.   if(!(pwc=malloc(sizeof(struct PrefsWinContext))))
  225.     return(NULL);
  226.   memset(pwc,0,sizeof(struct PrefsWinContext));
  227.   pwc->Dispose=PrefsWin_Dispose;
  228.   pwc->Handle=PrefsWin_Handle;
  229.   pwc->Hide=PrefsWin_Hide;
  230.   pwc->Show=PrefsWin_Show;
  231.  
  232.   pwc->Prefs=pg;
  233.  
  234.   if(!(pwc->ButtonWin=ButtonWin_Create(pg)))
  235.   {
  236.     pwc->Dispose(pwc);
  237.     return(NULL);
  238.   }
  239.  
  240.   if(!(pwc->ScrollWin=ScrollWin_Create(pg)))
  241.   {
  242.     pwc->Dispose(pwc);
  243.     return(NULL);
  244.   }
  245.  
  246.   return(pwc);
  247. }
  248.  
  249.  
  250. BOOL PrefsWin_Handle(struct PrefsWinContext *pwc,unsigned long sigs)
  251. {
  252.   BOOL cont=TRUE,close=FALSE;
  253.   long value;
  254.   char *string;
  255.   if(pwc)
  256.   {
  257.     if(sigs&(1<<pwc->Window->UserPort->mp_SigBit))
  258.     {
  259.       struct IntuiMessage *im;
  260.       while(im=GT_GetIMsg(pwc->Window->UserPort))
  261.       {
  262.         int class,code,id;
  263.         struct Gadget *gg;
  264.         class=im->Class;
  265.         code=im->Code;
  266.         switch(class)
  267.         {
  268.           case IDCMP_GADGETUP:
  269.             gg=(struct Gadget *)im->IAddress;
  270.             id=gg->GadgetID;
  271.             GT_ReplyIMsg(im);
  272.             switch(id)
  273.             {
  274.               case HOTKEY_ID:
  275.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTST_String,&string,TAG_DONE);
  276.                 pwc->Prefs->SetString(pwc->Prefs,"Hot Key",string);
  277.                 MyCx->SetHotKey(MyCx,string);
  278.                 break;
  279.               case XSPEED_ID:
  280.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTSL_Level,&value,TAG_DONE);
  281.                 pwc->Prefs->SetLong(pwc->Prefs,"XMouseSpeed",value);
  282.                 MyWM->MouseSpeedX=value;
  283.                 break;
  284.               case YSPEED_ID:
  285.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTSL_Level,&value,TAG_DONE);
  286.                 pwc->Prefs->SetLong(pwc->Prefs,"YMouseSpeed",value);
  287.                 MyWM->MouseSpeedY=value;
  288.                 break;
  289.               case CLICKFRONT_ID:
  290.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTCB_Checked,&value,TAG_DONE);
  291.                 pwc->Prefs->SetLong(pwc->Prefs,"ClickFront",value);
  292.                 MyWM->ClickToFront=value;
  293.                 break;
  294.               case CLICKBACK_ID:
  295.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTCB_Checked,&value,TAG_DONE);
  296.                 pwc->Prefs->SetLong(pwc->Prefs,"ClickBack",value);
  297.                 MyWM->ClickToBack=value;
  298.                 break;
  299.               case QUIT_ID:
  300.                 cont=FALSE;
  301.                 break;
  302.               case HIDE_ID:
  303.                 close=TRUE;
  304.                 break;
  305.               case SAVE_ID:
  306.                 pwc->Prefs->SetLong(pwc->Prefs,"MainTop",pwc->Window->TopEdge);
  307.                 pwc->Prefs->SetLong(pwc->Prefs,"MainLeft",pwc->Window->LeftEdge);
  308.                 if(pwc->ButtonWin->Window)
  309.                 {
  310.                   pwc->Prefs->SetLong(pwc->Prefs,"ButtTop",pwc->ButtonWin->Window->TopEdge);
  311.                   pwc->Prefs->SetLong(pwc->Prefs,"ButtLeft",pwc->Window->LeftEdge);
  312.                 }
  313.                 if(pwc->ScrollWin->Window)
  314.                 {
  315.                   pwc->Prefs->SetLong(pwc->Prefs,"ScrollTop",pwc->ScrollWin->Window->TopEdge);
  316.                   pwc->Prefs->SetLong(pwc->Prefs,"ScrollLeft",pwc->ScrollWin->Window->LeftEdge);
  317.                 }
  318.                 pwc->Prefs->Save(pwc->Prefs);
  319.                 break;
  320.               case SETBUTTONS_ID:
  321.                 pwc->ButtonWin->Show(pwc->ButtonWin);
  322.                 break;
  323.               case SETSCROLL_ID:
  324.                 pwc->ScrollWin->Show(pwc->ScrollWin);
  325.                 break;
  326.             }
  327.             break;
  328.           case IDCMP_CLOSEWINDOW:
  329.             GT_ReplyIMsg(im);
  330.             close=TRUE;
  331.             break;
  332.           case IDCMP_REFRESHWINDOW:
  333.             GT_ReplyIMsg(im);
  334.             GT_BeginRefresh(pwc->Window);
  335.             GT_EndRefresh(pwc->Window, TRUE);
  336.             break;
  337.           default:
  338.             GT_ReplyIMsg(im);
  339.             break;
  340.         }
  341.       }
  342.     }
  343.     else
  344.     {
  345.       pwc->ButtonWin->Handle(pwc->ButtonWin,sigs);
  346.       pwc->ScrollWin->Handle(pwc->ScrollWin,sigs);
  347.     }
  348.   }
  349.   if(close)
  350.     pwc->Hide(pwc);
  351.  
  352.   pwc->Signals=1<<pwc->Window->UserPort->mp_SigBit;
  353.   pwc->Signals|=pwc->ButtonWin->Signals;
  354.   pwc->Signals|=pwc->ScrollWin->Signals;
  355.  
  356.   return(cont);
  357. }
  358.  
  359.